opendir(DH,"/Users/yaping/Documents/workspace/result/ASM/") or die;
foreach my $file(readdir(DH)){
	if($file=~/methylCGsRich_ASM_(\w+)Merge_(\w+)_pValue.txt/){
		my $sample=$1;
		my $chr=$2;
		open(FH,"</Users/yaping/Documents/workspace/result/ASM/$file") or die;
		my @in=<FH>;
		chomp(@in);
		close(FH);
		my @out;
		my $count = 1;
		foreach my $line(@in){
			my @splitin = split "\t",$line;
			
			if($splitin[2] < 0.05){
				push(@out,"$line\n");
				foreach my $myline(@in){
					my @splitmyline = split "\t",$myline;
					if($splitmyline[2] < 0.05 && $splitmyline[0] == $splitin[0] && $splitmyline[1] != $splitin[1]){
						$count++;
					}
				}
				if($count <= 2){
					pop(@out);
				}
					
				$count = 1;
			}
		}
		my $out_file="methylCGsRich_ASM_".$sample."Merge_".$chr."_sigGroup.txt";
		open(OUT,">/Users/yaping/Documents/workspace/result/ASM/$out_file");
		print OUT @out;
		close(OUT);
		
	}
}
